import Vue from 'vue'
import Vuex from 'vuex'
import question from './module/question'
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    token: sessionStorage.getItem("token"),
    view: {
      userView: false,
      showView: '',
    },
    phone: sessionStorage.getItem("phone"),
    userInfo: sessionStorage.getItem("userInfo")
  },
  getters: {
    view: state => state.view,
  },
  mutations: {
    setToken(state, token) {
      state.token = token;
      sessionStorage.setItem("token", token);
    },
    clearToken(state) {
      state.token = null;
      sessionStorage.removeItem('token');
    },
    setUserInfo(state, str) {
      state.userInfo = str;
      sessionStorage.setItem("userInfo", str);
    },
    clearUserInfo(state) {
      state.userInfo = null;
      sessionStorage.removeItem("userInfo");
    },
    SET_VIEW: (state, view) => {
      state.view = view
    },
    SET_PHONE: (state, view) => {
      state.phone = view;
      sessionStorage.setItem("phone", view);
    },
  },
  actions: {
  },
  modules: {
    question
  }
})
